//
//  NiceQueueCollectionViewCell.m
//  HappyTrip
//
//  Created by dlios on 15-3-28.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "NiceQueueCollectionViewCell.h"

@implementation NiceQueueCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageView = [[UIImageView alloc] init];
        self.imageView.contentMode = UIViewContentModeScaleAspectFill;
        self.imageView.layer.cornerRadius = 5;
        self.imageView.clipsToBounds = YES;
        [self.contentView addSubview:self.imageView];
        [_imageView release];
        
        self.placeLabel = [[UILabel alloc] init];
        [self.imageView addSubview:self.placeLabel];
        self.placeLabel.textAlignment = NSTextAlignmentRight;
        self.placeLabel.textColor = [UIColor whiteColor];
        self.placeLabel.shadowColor = [UIColor blackColor];
        self.placeLabel.shadowOffset = CGSizeMake(1, 1);
        [_placeLabel release];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [super applyLayoutAttributes:layoutAttributes];
    CGFloat width = self.contentView.frame.size.width;
    CGFloat heigth = self.contentView.frame.size.height;
    
    self.imageView.frame = CGRectMake(0, 0, width, heigth);
    self.placeLabel.frame = CGRectMake(10, heigth - 30, width - 20, 20);
    
}

- (void)setNiceQueue:(NiceQueue *)niceQueue
{
    if (_niceQueue != niceQueue) {
        [_niceQueue release];
        _niceQueue = [niceQueue retain];
    }
    NSURL *url = [NSURL URLWithString:_niceQueue.photo];
    [self.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"picLoading.png"]];
    self.placeLabel.text = _niceQueue.city;
}

- (void)dealloc
{
    [_imageView release];
    [_placeLabel release];
    [super dealloc];
}

@end
